const { createUser,getUerInfo } = require('../service/user.service')

class UserController {
  async register(ctx, next) {
    // 1. 获取数据
    // console.log(ctx.request.body)
    // const { user_name, password } = JSON.parse(ctx.request.body)
    // console.log(typeof ctx.request.body, ctx.request.body, user_name, password);

   
    
    // 2. 操作数据库
    const res = await createUser(user_name, password)//添加新用户
    // console.log(res)
    // 3. 返回结果
    ctx.body = {
      code: 0,
      message: '用户注册成功',
      result: {
        id: res.id,
        user_name: res.user_name,
      },
    }
  }
  async login(ctx, next) {
    ctx.body = '登录成功'
  }
}

module.exports = new UserController()